<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>详情</title>

    <link rel="stylesheet" href="./node_modules/layui/dist/css/layui.css" />

    <script type="text/javascript" src="./node_modules/layui/dist/layui.js"></script>
    <script type="text/javascript" src="./node_modules/jquery/dist/jquery.min.js"></script>
    <script type="text/javascript" src="./js/site.js"></script>
    <script type="text/javascript" src="./js/config.js"></script>
</head>
<body style="margin: 10px;">
    <form class="layui-form">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">预计到校</label>
                <div class="layui-input-inline">
                    <input type="text" id="pentertime" name="pentertime" id="pentertime" autocomplete="off" class="layui-input">
                </div>
            </div>
            
            <div class="layui-inline">
                <label class="layui-form-label">处理结果</label>
                <div class="layui-input-inline">
                    <select id="rst" name="rst">
                        <option value="0">初始</option>
                        <option value="1">无效</option>
                        <option value="2">跟进</option>
                        <option value="3">有效</option>
                        <option value="4">重复</option>
                    </select>
                </div>
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block" style="margin-right: 20px;">
                <textarea id="cbrief" name="cbrief" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>
    </form>

    <div class="layui-input-block">
        <button id="btnSave" class="layui-btn">保存</button>
    </div>

    <script>
        $(document).ready(() => {
            let ck = new CookieSettings();
            let paras = ck.getUrlVars();
            let id = paras.id;
            let detail = new DetailOperation();

            detail.SetBrief(id);

            layui.form.render("select");
            layui.laydate.render({
                elem: "#pentertime"
            });

            $("#btnSave").on("click", () => {
                debugger;
                let formData = new FormData();

                formData.append("id", id);

                let pentertime = $("#pentertime").val();
                formData.append("pentertime", pentertime);

                let rst = $("#rst").val();
                formData.append("rst", rst);

                let cbrief = $("#cbrief").val();
                formData.append("cbrief", cbrief);

                let myUrl = apiurl + "/reg/infointro/cbrief";

                $.ajax({
                    url: myUrl,
                    type: 'PUT',
                    cache: false,
                    data: formData,
                    processData: false,
                    contentType: false
                }).done(function (res) {
                    layer.alert("保存成功！" + id);
                }).fail(function (res) {
                    layer.alert("保存失败！" + id);
                });


            });
        });

        function DetailOperation() {
            this.SetBrief = function(id) {
                let myUrl = apiurl + "/reg/infointro/" + id;

                $.ajax({
                    url: myUrl,
                    type: 'GET',
                    cache: false,
                    processData: false,
                    contentType: false
                }).
                done(function (res) {
                    console.log(res);
                    $("#pentertime").val(res.pentertime);
                    $("#cbrief").val(res.cbrief);
                    $("#rst").val(res.rst);
                    layui.form.render("select");
                }).
                fail(function (res) {
                    $("#pentertime").val("");
                    $("#cbrief").val("");
                    $("#rst").val("");
                    layui.form.render("select");
                });

            }
        }
    </script>
</body>
</html>